package org.feifei.quartz.service.impl;

import org.feifei.quartz.dto.QuartzJobInfo;
import org.feifei.quartz.job.MainJob;
import org.feifei.quartz.service.QuartzService;
import org.feifei.quartz.util.QuartzUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author forever
 * @Description: QuartzService的实现类
 * @date 2021/12/19 14:40
 */
@Service
public class QuartzServiceImpl implements QuartzService {


    @Autowired
    private SchedulerFactoryBean factoryBean;

    @Override
    public void add(QuartzJobInfo jobInfo) {
        QuartzUtils.addJob(factoryBean.getScheduler(), jobInfo.getJobName(),
                MainJob.class, jobInfo, jobInfo.getCronj());
    }

    @Override
    public void del(String name) {
        QuartzUtils.removeJob(factoryBean.getScheduler(), name);
    }
}
